/***************************************************************************
 *   Copyright (C) 2007 by Warren Kenny   *
 *   warren.kenny@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef OTAPACKETCAPTURE_H
#define OTAPACKETCAPTURE_H

/**
	@author Warren Kenny <warren.kenny@gmail.com>
*/

#define OTA_PACKET_CAPTURE_FILTER_LENGTH 300

#include <pcap.h>

#ifndef WIN32

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/if_ether.h>
#include <net/ethernet.h>
#include <netinet/ether.h>

#else

#include <WinSock2.h>

#endif

#include <otaCore.h>
#include <otaConfigReader.h>

class otaPacketCapture
{
public:
	
	otaPacketCapture();
	
	void listCaptureDevices();
	
	bool init( otaConfigReader& config );
	
	bool selectCaptureDevice( std::string captureDevice );
	
	bool compileCaptureFilter( std::string captureFilter );
	
	void activateCapture( pcap_handler callbackFunction, u_char *arguments );
	
	~otaPacketCapture();
    
private:
	
	std::string 		m_captureDevice;
	char			m_filter[OTA_PACKET_CAPTURE_FILTER_LENGTH];
	char 			m_errorString[PCAP_ERRBUF_SIZE];
	struct bpf_program 	m_compiledFilter;						
	pcap_if_t*		m_deviceList;								
	pcap_t*			m_captureHandle;			   						
	bpf_u_int32 		m_netMask;								
	bpf_u_int32 		m_localAddress;								
	std::string 		m_host;
};

#endif
